package com.example.mall.service.impl;

import com.example.mall.mbg.mapper.CustomSupplierMapper;
import com.example.mall.mbg.mapper.SupplierMapper;
import com.example.mall.mbg.model.Supplier;
import com.example.mall.mbg.model.SupplierExample;
import com.example.mall.service.SupplierService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SupplierServiceImpl
 * Created by on 2023/12/27.
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private CustomSupplierMapper customSupplierMapper;

    @Override
    public List<Supplier> listAll() {
        return supplierMapper.selectByExample(new SupplierExample());
    }

    @Override
    public int create(Supplier supplier) {
        return supplierMapper.insertSelective(supplier);
    }

    @Override
    public int update(Integer supplierid, Supplier supplier) {
        supplier.setSupplierid(supplierid);
        return supplierMapper.updateByPrimaryKeySelective(supplier);
    }

    @Override
    public int delete(Integer supplierid) {
        return supplierMapper.deleteByPrimaryKey(supplierid);
    }

    @Override
    public List<Supplier> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return supplierMapper.selectByExample(new SupplierExample());
    }

    @Override
    public Supplier get(Integer supplierid) {
        return supplierMapper.selectByPrimaryKey(supplierid);
    }

    @Override
    public int getNextId() {
        return customSupplierMapper.getNextId();
    }

    @Override
    public Supplier getSupplierByName(String supplierName) {
        return customSupplierMapper.getSupplierByName(supplierName);
    }
}
